import lejos.nxt.*;
import lejos.robotics.subsumption.*;

public class LeftWall implements Behavior {
    private UltrasonicSensor sonar;
    private boolean suppressed = false;
    
    public LeftWall(SensorPort port)
    {
       sonar = new UltrasonicSensor(port);
    }

    public boolean takeControl() {
       return (sonar.getDistance() < 25) && (Motor.B.getTachoCount() < 0);
    }

    public void suppress() {
       suppressed = true;
    }

    public void action() {
       suppressed = false;
       LCD.clear(3);
       LCD.drawString("Left wall detected", 0, 3);
       Motor.B.rotate(180, true);

       while( Motor.B.isMoving() && !suppressed )
         Thread.yield();

       Motor.B.stop();
    }
}
